package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCollectMapper;
import com.qf.pojo.DtsCollect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.service
 * @Description:
 * @Date 2022/7/8 21:02
 */
@Service
public class CollectServiceImpl implements CollectService {

     @Autowired
    private DtsCollectMapper mapper;
    @Override
    public IPage<DtsCollect> list(String userId,String valueId,Integer page,Integer limit,String sort,String order) {

        IPage<DtsCollect> page1 = new Page(page,limit);

        QueryWrapper<DtsCollect> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted", false);
         if(!StringUtils.isEmpty(userId)){
             queryWrapper.eq("user_id", userId);
         }
         if(!StringUtils.isEmpty(valueId)){
             queryWrapper.eq("value_id", valueId);
         }
         if(!StringUtils.isEmpty(sort)&&!StringUtils.isEmpty(order)){

             if(order.equalsIgnoreCase("asc")){
                 queryWrapper.orderByAsc();
             }else {
                 queryWrapper.orderByDesc();
             }
         }
        IPage<DtsCollect> dtsCollectIPage = mapper.selectPage(page1, queryWrapper);
        return dtsCollectIPage;
    }
}
